/**
 * //English description is not available for the problem. Please switch to
 * //Chinese.
 * // Related Topics 数组 动态规划 矩阵 👍 320 👎 0
 */

package com.xixi.basicAlgroithms.dynamicPrograming;

public class ID_Offer_47_LiWuDeZuiDaJieZhiLcof {
    public static void main(String[] args) {
        Solution solution = new ID_Offer_47_LiWuDeZuiDaJieZhiLcof().new Solution();
    }


    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int maxValue(int[][] grid) {

            int m = grid.length;
            int n = grid[0].length;

            int[][] status = new int[m][n];
            status[0][0] = grid[0][0];

            //初始化第一列
            for (int i = 1; i < m; ++i) {
                status[i][0] = status[i - 1][0] + grid[i][0];
            }

            //初始化第一行
            for (int j = 1; j < n; ++j) {
                status[0][j] = status[0][j - 1] + grid[0][j];
            }

            //动态规划
            for (int i = 1; i < m; i++) {
                for (int j = 1; j < n; ++j) {
                    status[i][j] = Math.max(status[i - 1][j], status[i][j - 1]) + grid[i][j];
                }
            }

            return status[m - 1][n - 1];
        }
    }
//leetcode submit region end(Prohibit modification and deletion)


}